package Part2_自定义泛型;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * ClassName: Demo
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.04.18 15:45
 */
public class Demo {
    @Test
    public void test1(){
        Order<String> o1 = new Order<>("Tom", 18283207);
        System.out.println(o1);
        String t1 = o1.getT();


        Order o2 = new Order<>('u', 18283207);//自动类型判断
        System.out.println(o2.getT().getClass());//java.lang.Character
        Character t2 = (Character) o2.getT();
        //或者Object t2 = o2.getT();
    }

    @Test
    public void test2(){

        //继承传递父类泛型
        SubOrder1<String> order1 = new SubOrder1<>();
        String t1 = order1.getT();

        //确定父类泛型，子类加入新泛型
        SubOrder2<Character> order2 = new SubOrder2<>();
        Character e = order2.getE();
        Integer t2 = order2.getT();

        //传递父类泛型，并加入新泛型
        SubOrder3<String, Integer> order3 = new SubOrder3<>();
        String t3 = order3.getT();
        Integer e1 = order3.getE();
        int orderID = order3.getOrderID();
    }

    @Test
    public void test3(){
        Order<String> o1 = new Order<>("Tom", 18283207);

        Character[] chars = new Character[]{'1','w','r','!'};
        ArrayList<Character> copiedList = o1.copy(chars);

        for(Character c : copiedList){
            System.out.println(c);
        }
    }
}
